package com.cqcetbbs.smartlab.cqcetbbs.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.cqcetbbs.smartlab.cqcetbbs.R;
import com.cqcetbbs.smartlab.cqcetbbs.javabean.ArtlistInfos;

import java.util.List;

import static com.cqcetbbs.smartlab.cqcetbbs.R.id.img;
import static com.cqcetbbs.smartlab.cqcetbbs.R.id.tv_title;

/**
 * Created by user on 2017/10/25.
 */

public class ArtlistApadter extends BaseAdapter {

    Context context;
    List<ArtlistInfos.ArtlistInfo> ArtlistInfoList;

    public ArtlistApadter( Context context,List<ArtlistInfos.ArtlistInfo> ArtlistInfoList){
        this. context = context;
        this. ArtlistInfoList = ArtlistInfoList;
    }

    @Override
    public int getCount() {
        return ArtlistInfoList.size();
    }

    @Override
    public Object getItem(int i) {
        return ArtlistInfoList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup viewGroup) {

        ViewHolder viewHolder = null;
        if (convertView == null) {
            viewHolder = new ViewHolder();
            convertView = View.inflate(context, R.layout.fragment_detail_item, null);
            viewHolder.tv_title = convertView.findViewById(tv_title);
            viewHolder.tv_time = convertView.findViewById(R.id.tv_time);
            viewHolder.tv_read = convertView.findViewById(R.id.tv_read);
            viewHolder.img = convertView.findViewById(img);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        Glide.with(context).load(ArtlistInfoList.get(position).getPic()).centerCrop().into(viewHolder.img);
        viewHolder.tv_title.setText(ArtlistInfoList.get(position).getTitle());
        viewHolder.tv_time.setText(ArtlistInfoList.get(position).getUp_time());
        viewHolder.tv_read.setText("阅读量:"+ArtlistInfoList.get(position).getClick());

        return convertView;
    }


    public static class ViewHolder {
        TextView tv_title;
        TextView tv_read;
        TextView tv_time;
        ImageView img;
    }
}
